home *** CD-ROM | disk | FTP | other *** search
-
- (define biblioteca-environment
- (make-environment
- (define (string-CI<=? x y)
- (or (string-CI<? x y)
- (string-CI=? x y)))
- (define (make-persona nome cognome)
- (cons nome cognome))
- (define (get-nome-P persona)
- (car persona))
- (define (get-cognome-P persona)
- (cdr persona))
- (define (input-persona)
- (define cognome (read-string "cognome: "))
- (define nome (read-string "nome: "))
- (make-persona nome cognome))
- (define (output-persona persona)
- (writeln "cognome : " (get-cognome-P persona))
- (writeln "nome : " (get-nome-P persona)))
- (define (persona=? persona1 persona2)
- (and (string-CI=? (get-nome-P persona1)
- (get-nome-P persona2))
- (string-CI=? (get-cognome-P persona1)
- (get-cognome-P persona2))))
- (define (persona<=? persona1 persona2)
- (cond ((string-CI<? (get-cognome-P persona1)
- (get-cognome-P persona2)) #t)
- ((and (string-CI=? (get-cognome-P persona1)
- (get-cognome-P persona2))
- (string-CI<=? (get-nome-P persona1)
- (get-nome-P persona2))) #t)
- (else #f)))
- (define (make-libro autori titolo)
- (list autori titolo nil))
- (define (get-autore-L libro)
- (car libro))
- (define (get-titolo-L libro)
- (cadr libro))
- (define (get-collocazione-L libro)
- (caddr libro))
- (define (set-collocazione-L! libro collocazione)
- (set-car! (cddr libro) collocazione))
- (define (input-libro)
- (define aut-lis nil)
- (define titolo nil)
- (writeln "Autori")
- (set! aut-lis (input-aut-lis))
- (set! titolo (read-string "titolo: "))
- (make-libro aut-lis titolo))
- (define (input-aut-lis)
- (define nome (input-persona))
- (if (conferma? "un altro autore ? ")
- (merge-aut (list nome) (input-aut-lis))
- (list nome)))
- (define (merge-aut x y)
- (cond ((null? x) y)
- ((null? y) x)
- ((persona<=? (car y) (car x))
- (cons (car x) (merge-aut (cdr x) y)))
- (else (cons (car y) (merge-aut x (cdr y))))))
- (define (output-aut-lis aut-lis)
- (for-each output-persona aut-lis))
- (define (output-libro libro)
- (writeln "titolo : " (get-titolo-L libro))
- (writeln "Autori")
- (output-aut-lis (get-autore-L libro))
- (newline)
- (writeln "collocazione : " (get-collocazione-L libro)))
- (define titolo=? string-CI=?)
- (define data=? =)
- (define data<=? <=)
- (define collocazione=? string=?)
- (define (aut-lis=? aut1 aut2)
- (cond ((and (null? aut1) (null? aut2)) #t)
- ((null? aut1) #f)
- ((null? aut2) #f)
- ((persona=? (car aut1) (car aut2))
- (aut-lis=? (cdr aut1) (cdr aut2)))
- (else #f)))
- (define (aut-lis<=? aut1 aut2)
- (cond ((and (null? aut1) (null? aut2)) #t)
- ((null? aut1) #f)
- ((null? aut2) #t)
- ((persona=? (car aut1) (car aut2))
- (aut-lis<=? (cdr aut1) (cdr aut2)))
- (else (persona<=? (car aut1) (car aut2)))))
- (define (make-volume libro data casa-ed)
- (list libro data casa-ed nil))
- (define (get-libro-V volume)
- (car volume))
- (define (get-data-V volume)
- (cadr volume))
- (define (get-casa-ed-V volume)
- (caddr volume))
- (define (get-prestiti-V volume)
- (cadddr volume))
- (define (get-last-pres-V volume)
- (car (cadddr volume)))
- (define (add-prestito-V! volume data)
- (set-car! (cdddr volume) (cons data (cadddr volume))))
- (define (output-volume volume)
- (define da-re (get-data-res-D (get-last-pres-V volume)))
- (newline)
- (output-libro (get-libro-V volume))
- (writeln "data di pubblicazione : " (get-data-V volume))
- (writeln "casa editrice : " (get-casa-ed-V volume))
- (if (or (null? da-re) (data? da-re))
- (writeln "Disponibile per il prestito")
- (writeln "In prestito dal "
- (get-data-pre-D (get-last-pres-V volume)))))
- (define (input-volume)
- (define libro (input-libro))
- (define data (read-number "data di pubblicazione: "))
- (define casa (read-string "casa editrice: "))
- (make-volume libro data casa))
- (define (volume-autore=? volume1 volume2)
- (aut-lis=? (get-autore-L (get-libro-V volume1))
- (get-autore-L (get-libro-V volume2))))
- (define (volume-autore<=? volume1 volume2)
- (aut-lis<=? (get-autore-L (get-libro-V volume1))
- (get-autore-L (get-libro-V volume2))))
- (define (volume=? volume1 volume2)
- (and (aut-lis=? (get-autore-L (get-libro-V volume1))
- (get-autore-L (get-libro-V volume2)))
- (titolo=? (get-titolo-L (get-libro-V volume1))
- (get-titolo-L (get-libro-V volume2)))
- (data=? (get-data-V volume1)
- (get-data-V volume2))))
- (define (make-utente persona indirizzo)
- (list persona indirizzo (cons nil nil)))
- (define (get-persona-U utente)
- (car utente))
- (define (get-indirizzo-U utente)
- (cadr utente))
- (define (get-prestiti-U utente)
- (cdaddr utente))
- (define (find-pres-U collocazione utente)
- (define (F-P-U n p)
- (if (null? p)
- nil
- (if (collocazione=? collocazione
- (get-collocazione-L (get-libro-P (car p))))
- n
- (F-P-U (1+ n) (cdr p)))))
- (F-P-U 0 (get-prestiti-U utente)))
- (define (get-pres-U n utente)
- (list-ref (cdaddr utente) n))
- (define (rem-pres-U! n utente)
- (if (= n 0)
- (set-cdr! (caddr utente)
- (cdr (cdaddr utente)))
- (set-cdr! (list-tail (cdaddr utente) (-1+ n))
- (list-tail (cdaddr utente) n))))
- (define (get-restituiti-U utente)
- (cdaddr utente))
- (define (add-prestiti-U! restituito utente)
- (set-cdr! (caddr utente) (cons restituito (cdaddr utente))))
- (define (add-restituiti-U! prestito utente)
- (set-car! (caddr utente) (cons prestito (caaddr utente))))
- (define (input-utente)
- (define persona (input-persona))
- (define indirizzo (read-string "indirizzo: "))
- (make-utente persona indirizzo))
- (define (output-prestiti prestiti)
- (if (null? prestiti)
- nil
- (begin (output-libro (get-libro-P (car prestiti)))
- (writeln "Prestato il "
- (get-data-pre-D (get-data-P (car prestiti))))
- (output-prestiti (cdr prestiti)))))
- (define (output-utente utente)
- (newline)
- (output-persona (get-persona-U utente))
- (writeln "indirizzo : " (get-indirizzo-U utente))
- (writeln "libri attualmente in prestito : "
- (length (get-prestiti-U utente))))
- (define (utente=? utente1 utente2)
- (persona=? (get-persona-U utente1)
- (get-persona-U utente2)))
- (define (utente<=? utente1 utente2)
- (persona<=? (get-persona-U utente1)
- (get-persona-U utente2)))
- (define (make-prestito libro data)
- (cons libro data))
- (define (get-libro-P prestito)
- (car prestito))
- (define (get-data-P prestito)
- (cdr prestito))
- (define (make-data data-pre data-res)
- (cons data-pre data-res))
- (define (get-data-pre-D data)
- (car data))
- (define (get-data-res-D data)
- (cdr data))
- (define (set-data-res-D! data data-res)
- (set-cdr! data data-res))
- (define data<=? <=)
- (define (data? data)
- (number? data))
- (define (make-biblio arc pos)
- (list 'archivio arc pos (arc 'us-data nil)))
- (define (get-arc v)
- (cadr v))
- (define (get-pos v)
- (caddr v))
- (define (get-data v)
- (cadddr v))
- (define (set-data! v p)
- (set-car! (cdddr (cdr v)) p))
- (define (get-next-col v)
- (caddr (get-data v)))
- (define (get-type v)
- (car (get-data v)))
- (define (get-sigla v)
- (cadr (get-data v)))
- (define (set-pos! v p)
- (set-car! (cddr v) p))
- (define (set-next-col! v p)
- (set-car! (cddr (get-data v)) p))
- (define (archivio? val)
- (and (pair? val) (eq? (car val) 'archivio)))
- (define (conferma? messaggio)
- (define risposta nil)
- (display messaggio)
- (set! risposta (read))
- (or (eq? risposta 'y)
- (eq? risposta 's)))
- (define (read-string text) ;
- (do ((lettura (begin (display text)
- (read))
- (begin (display text)
- (read))))
- ((string? lettura) lettura)
- (writeln "il dato richiesto deve essere una stringa")))
- (define (read-number text)
- (do ((lettura (begin (display text)
- (read))
- (begin (display text)
- (read))))
- ((number? lettura) lettura)
- (writeln "il dato richiesto deve essere un numero")))))
-
-